package demo.controller;

import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import demo.dao.IProductDao;
import demo.model.Product;

@RestController
@RequestMapping("product")
public class ProductController {
	
	@Resource
	private IProductDao dao;

	//上传图片
	@RequestMapping("/upload.do")
	public Map upload(MultipartFile file) {
		//获取文件原始名
		String name = file.getOriginalFilename();
		System.out.println(name); 
		String path = "d:\\upload\\"+name;
		try {
			file.transferTo(new File(path));
		} catch (IllegalStateException | IOException e) {
			e.printStackTrace();
		}
		Map<String,Object> map = new HashMap<String, Object>();
		map.put("code", 0);
		map.put("msg", "");
		map.put("data",name);
		return map;
	}
	
	@RequestMapping("editUrl.do")
	public int editUrl(Product p) {
		return dao.editUrl(p);
	}
}
